// 处理初始化模版
import React from 'react';

import {
    promptBox
} from 'nc-lightapp-front';

import deepCopy from '../../../../public/functions/deep-copy';

import language from '../../language';


// 初始化处理template数据
export default function processTemplate(template, btnConf = []) {
    template['ncc60071701list'].items.map((item, index) => {
        // item.width = '120px';
    });

    let editConf = btnConf.find(btn => btn.key === 'Edit');
    let delConf = btnConf.find(btn => btn.key === 'Delete');
    if (editConf || delConf) {
        template['ncc60071701list'].items.push({
            itemtype: 'customer',
            label: language['hi6007-000029'],/* 国际化处理： 操作*/
            visible: true,
            width: editConf && delConf ? '120px' : '80px',
            fixed: 'right',
            attrcode: 'operation',
            render: (text, record, index) => {
                return (
                    <div>
                        {editConf && <a
                            href="javascript:void(0)"
                            className="operator-btn"
                            onClick={(e) => {
                                e.stopPropagation();
                                this.setState({
                                    selectedRows: [{data: record}],
                                    pageFrom: 'modify'
                                }, () => {
                                    this.toEditPage('modify');
                                });
                            }}
                        >
                            {editConf['title']}
                        </a>}
                        {delConf && <a
                            href="javascript:void(0)"
                            className="operator-btn"
                            onClick={(e) => {
                                e.stopPropagation();
                                this.setState({
                                    // 为了和选中的数据对应上
                                    selectedRows: [{data: record}]
                                }, () => {
                                    this.deleteMainTableRow();
                                });
                            }}
                        >
                            {delConf['title']}
                        </a>}
                    </div>
                );
            }
        });
    }

    template['gridrelation']['sort'] = {
        destBrowseAreaCode: null,
        destEditAreaCode: null,
        srcAreaCode: 'sort',
        tabRelation: []
    }

    template['hi_psnjob_h'] && (template['hi_psnjob_h'].relationcode = 'bd_psndoc');
    template['hi_psnorg_h'] && (template['hi_psnorg_h'].relationcode = 'bd_psndoc');

    template['hi_psnjob_history'] = deepCopy(template.hi_psnjob);

    template['createuser'].items.map((item) => {
        item.width = '120px';
    });

    // 隐藏照片
    template['bd_psndoc'].items.map((item) => {
        if (item.attrcode === 'photo') {
            item.visible = false
        }
    });

    return template
}
